import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;

public class UserClient {
    private Socket client;

    public UserClient(String ip,int port) throws IOException, IOException {
        this.client=new Socket(ip,port);
    }
    public void sendMsg(Message<User> message) throws IOException{
        MessageUtil.sendMsg(client,message);
    }
    public String receiveMsg()throws IOException,ClassNotFoundException{
        Message<String> msg=MessageUtil.receiveMsg(client);
        return msg.getData();
    }
    public static void main(String[] args) {
        try {
            UserClient client = new UserClient("localhost", 8888);
            User user=new User("admin","123456");
            client.sendMsg(new Message<User>("register",user));
            String backMsg=client.receiveMsg();
        }catch(IOException e){
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
